package spider.cluster.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import spider.zookeeper.monitor.ClusterMonitor;
import spider.zookeeper.node.Node;

/**
 * ClusterController
 *
 * @author Archx[archx@foxmail.com]
 * @date 2017/4/9.
 */
@Controller
@RequestMapping("/chat")
public class ChatController {

    @Autowired
    private ClusterMonitor monitor;

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login() {
        return "login";
    }

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public String register(@RequestParam("uid") String uid, Model model) {
        model.addAttribute("uid", uid);
        model.addAttribute("title", "Chat");
        return "chat";
    }

    @RequestMapping(value = "/node")
    @ResponseBody
    public Node code() {
        return monitor.selectServer();
    }
}
